/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.factory;

import java.util.Arrays;
import ru.jSkyRoom.filter.MatcherFilter;
import ru.jSkyRoom.filter.Filter;
import ru.jSkyRoom.filter.FilterChain;
import ru.jSkyRoom.filter.FilterChainBuilder;
import ru.jSkyRoom.interfaces.major.Major;
import ru.rakev.matcher.Matcher;

/**
 *
 * @author Rakev
 */
public class FilterFactory {

    private static FilterFactory instance = new FilterFactory();

    public static FilterFactory create() {
        return instance;
    }

    protected FilterFactory() {
    }

    public <E extends Major> Filter<E> create(Filter<E>... filters) {
        return new FilterChain<>(Arrays.asList(filters));
    }

    public <E extends Major> Filter<E> create(String... regexEDIDs) {
        FilterChainBuilder<E> builder = new FilterChainBuilder<>();
        for (String regex : regexEDIDs) {
            Filter filter = create(regex);
            builder.add(filter);
        }
        return builder.build();
    }

    public <E extends Major> Filter<E> create(final String regexEDID) {
        Matcher<E> tester = gerMajorMatcher().create(regexEDID);
        return new MatcherFilter<>(tester);
    }

    public <E extends Major> Filter<E> create(Matcher<E> matcher) {
        return new MatcherFilter<>(matcher);
    }

    private MajorMatcherFactory gerMajorMatcher() {
        return new MajorMatcherFactory();
    }
}
